package com.collect.zambia.zhiScene.zhiRemind.zhiRecall;

import android.content.Context;

import com.collect.zambia.zhiBase.BasePresenter;
import com.collect.zambia.zhiBase.BaseSubscriber;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRMarkedCustomerFollowUserListEntity;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRWaitCustomerFollowUserListEntity;
import com.collect.zambia.zhiBean.zhiSend.ZHISendEntity;
import com.collect.zambia.zhiBean.zhiSend.ZHISMarkCustomerFollowUser;
import com.collect.zambia.zhiNetApi.ZHIHttpApiProvider;
import com.collect.zambia.zhiNetApi.ZHIHttpResponse;
import com.collect.zambia.zhiUtils.RxSchedulers;

import java.util.ArrayList;

import javax.inject.Inject;

public class ZHIRecallPresenter extends BasePresenter<ZHIRecallContract.View> implements ZHIRecallContract.Presenter {

    @Inject
    public ZHIRecallPresenter() {

    }

    @Override
    public void getLatestWaitCustomerFollowUserListV2(Context context, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRWaitCustomerFollowUserListEntity>>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRWaitCustomerFollowUserListEntity>>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ArrayList<ZHIRWaitCustomerFollowUserListEntity> zhirWaitCustomerFollowUserListEntities = (ArrayList<ZHIRWaitCustomerFollowUserListEntity>) object;
                            mView.onGetLatestWaitCustomerFollowUserListV2(zhirWaitCustomerFollowUserListEntities);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().waitCustomerFollowUserList(new ZHISendEntity())
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void getLatestMarkedCustomerFollowUserList(Context context, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRMarkedCustomerFollowUserListEntity>>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRMarkedCustomerFollowUserListEntity>>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ArrayList<ZHIRMarkedCustomerFollowUserListEntity> zhirMarkedCustomerFollowUserListEntities = (ArrayList<ZHIRMarkedCustomerFollowUserListEntity>) object;
                            mView.onGetLatestMarkedCustomerFollowUserList(zhirMarkedCustomerFollowUserListEntities);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markedCustomerFollowUserList(new ZHISendEntity())
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void markCustomerFollowUser(Context context, ZHISMarkCustomerFollowUser zhisMarkCustomerFollowUser, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onMarkCustomerFollowUser();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markCustomerFollowUser(zhisMarkCustomerFollowUser)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
